package cn.harry.modular.achievement.controller;

import cn.harry.common.api.R;
import cn.harry.component.security.utils.SecurityUtils;
import cn.harry.modular.achievement.service.AchievementService;
import cn.harry.modular.achievement.vo.EchartsOptionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author harry
 * @公众号 Harry技术
 */
@Tag(name = "报表")
@RestController
@RequestMapping("/index")
@RequiredArgsConstructor
public class IndexController {
    private final AchievementService achievementService;

    @Operation(summary = "获取我的成果")
    @GetMapping(value = "/my")
    public R<EchartsOptionVO> myAchievement() {
        long userId = SecurityUtils.getUserId();
        return R.success(achievementService.myAchievement(userId));
    }

//    剩下的那三个图表在管理员加，1.从类型方面统计各类成果数量的柱状图 2.统计成果下载数量，就统计最高的前五个 3.饼图统计各个老师的成果数量占比

    @Operation(summary = "从类型方面统计各类成果数量的柱状图")
    @GetMapping(value = "/type")
    public R<EchartsOptionVO> typeAchievement() {
        return R.success(achievementService.typeAchievement());
    }

    @Operation(summary = "统计成果下载数量，就统计最高的前五个")
    @GetMapping(value = "/downloadTop5")
    public R<EchartsOptionVO> downloadTop5Achievement() {
        return R.success(achievementService.downloadTop5Achievement());
    }

    @Operation(summary = "饼图统计各个老师的成果数量占比")
    @GetMapping(value = "/teacherAchievement")
    public R<List<Map<String, Object>>> teacherAchievement() {
        List<Map<String, Object>> list = achievementService.teacherAchievement();
        return R.success(list);
    }
}
